<?php
require "model/usersreg.php";
//验证注册信息并进行注册
class LogintestController{
    function test(){
        $username=$_POST["username"];
        $password0=$_POST["password"];
        $db=new mydb();
        $sql="select * from usersreg WHERE username = '$username'";
        $arr=$db->doquery($sql);
        $obj1=new users();
        $id=$obj1->getid($arr);
        $password=$obj1->getpassword($arr);
        $rand=$obj1->getrand($arr);
        $admin=$obj1->getadmin($arr);
        $password1=md5($password0.$rand);
        if($password1!=$password)
        {
            echo 1;//密码错误
        }else{
            $token=md5(rand(1000,9999));
            setcookie('token',$token,time()+60);
            session_start();
            $_SESSION[$token]=$id;
            if($admin==0)
            {
                echo 2;//登陆成功(普通用户)
            }elseif($admin==1){
                $_SESSION[$token]=$username;
                echo 3;//管理员登录
            }
        }

    }
}
?>